﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DEMO.WCF_API.Services
{
    public class EXMessageContractSVC : DEMO.WCF_API.Contracts.IEXMessageContract
    {
        public DEMO.WCF_API.Contracts.EXMessageContract getEmployees(DEMO.WCF_API.Contracts.EXMessageContract oEXMessageContract)
        {
            try
            {
                if (oEXMessageContract==null || oEXMessageContract.Key==null|| !oEXMessageContract.Key.Equals("Password@strong"))
                {
                    throw new System.ServiceModel.FaultException("Not Authorized Key",new System.ServiceModel.FaultCode("2"));
                }
                DEMO.DataLayer.DEMOEntities db = new DEMO.DataLayer.DEMOEntities();
                var Employees = (from p in db.DM_Employee
                                join c in db.DM_EmployeeDetail on p.DME_ID equals c.DMED_DME_ID
                                where p.DME_Flag == 1
                                select new DEMO.WCF_API.Contracts.EXMessageContract
                                {
                                    Key = oEXMessageContract.Key,
                                    oEmployee = new Contracts.Employee()
                                    {
                                        Email = p.DME_EmailID,
                                        EmployeeID = p.DME_ID,
                                        Name = c.DMED_FName + " " + c.DMED_LName
                                    },
                                    Password = p.DME_Password
                                }).FirstOrDefault();
                return Employees;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }
}